layui.use(['form', 'laydate', 'miniTab'], function () {
    var form = layui.form
        , laydate = layui.laydate;

    //日期
    laydate.render({
        elem: '#project-date'
        , value: ad.date.formatterDate(new Date())
    });

    //自定义验证规则
    form.verify({
        project: function (value) {
            if (value.length < 5) {
                return '标题至少得5个字符啊';
            }
        }
    });

    //监听提交
    form.on('submit(submit)', function (data) {
        data = data.field;
        globalObj.addProject(data);
        return false;
    });

});

var globalObj = globalObj || {};
globalObj = $.extend(globalObj, {
    addProject: function (data) {
        (new globalObj.Request(globalObj.url)).setParams({
            param: {
                project: data.project,
                town: data.town,
                projectDate: data.projectDate,
                projectType: data.projectType
            },
            serviceId: "app.project.add"
        }).do().success(function (data) {
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            parent.layer.close(index); //再执行关闭
        });
    }
});